package com.example.myapplication.Entity;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.myapplication.R;

import java.util.List;

public class BlueToothAdapter extends BaseAdapter {
    private final Context mContext;
    private final List<BluetoothDevice> mItemList;
    public  BlueToothAdapter(Context context, List<BluetoothDevice> itemList) {
        mContext = context;
        mItemList = itemList;
    }

    @Override
    public int getCount() {
        return mItemList.size();
    }

    @Override
    public Object getItem(int position) {
        return mItemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("MissingPermission")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.ble_name_box, parent, false);
        }
        TextView title = (TextView) view.findViewById(R.id.ble_name);
        TextView subtitle = (TextView) view.findViewById(R.id.ble_addr);
        title.setText(mItemList.get(position).getName());
        subtitle.setText(mItemList.get(position).getAddress());
        return view;
    }

}